import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';

//pico板载资源..........................................................................................................................................
export const xnr_board_bootsel = function () {
    var code = 'BOOTSEL';
    return [code, Blockly.Arduino.ORDER_ATOMIC];
}

export const xnr_board_temp = function () {
    var code = 'analogReadTemp()';
    return [code, Blockly.Arduino.ORDER_ATOMIC];
}

//蓝牙.....................................................................................................................................................
export const serialBT_Init = function () {
    var content = Blockly.Arduino.valueToCode(this, 'CONTENT', Blockly.Arduino.ORDER_ATOMIC) || Profile.default.serial;
    Blockly.Arduino.definitions_['include_SerialBT'] = '#include <SerialBT.h>';
    Blockly.Arduino.setups_['setup_serial_BT'] = 'SerialBT.begin(' + content + ');';
    return '';
}

export const xnr_serialBT_SerialBT = function () {
    var code = 'SerialBT';
    return [code, Blockly.Arduino.ORDER_ATOMIC];
}

export const xnr_serialBT_available = function () {
    var code = 'SerialBT.available()';
    return [code, Blockly.Arduino.ORDER_ATOMIC];
}

export const xnr_serialBT_read = function () {
    var code = 'SerialBT.read()';
    return [code, Blockly.Arduino.ORDER_ATOMIC];
}

export const xnr_serialBT_write = function () {
    var value_data = Blockly.Arduino.valueToCode(this, 'data', Blockly.Arduino.ORDER_ATOMIC);
    var code = 'SerialBT.write('
        + value_data
        + ');\n';
    return code;
}

export const xnr_serialBT_init = function () {
    var value_value = Blockly.Arduino.valueToCode(this, 'value', Blockly.Arduino.ORDER_ATOMIC);
    Blockly.Arduino.definitions_['include_' + 'SerialBT'] = '#include <SerialBT.h>';
    Blockly.Arduino.setups_['begin'] = 'SerialBT.begin('
        + value_value
        + ');';
    var code = '';
    return code;
}